<?php
namespace My\Controller;

use Utuo\BackgroundController;
use Utuo\DistributionShopDonate;

class DistributionShopDonateController extends BackgroundController
{

    public function _initialize()
    {
        $this->setControllerTitle('捐赠管理');
        $this->setActionTitle(array(
            'index' => '捐赠列表',
            'config' => '捐赠配置',
            'project' => '公益项目列表',
            'addProject' => '添加公益项目',
            'modifyProject' => '修改公益项目'
        ));
        $this->setActionNav('config,index,project,addProject');
    }

    public function indexAction()
    {
        $pagesize = $this->getPageSize();
        $itemLists = DistributionShopDonate::getLists(array(
            'cid' => $this->aid
        ), $this->getPage(), $pagesize);
        $donateSum = DistributionShopDonate::getSum(array(
            'cid' => $this->aid
        ));
        $this->showPage($itemLists['count'], $pagesize);
        $this->assign('donateSum', $donateSum);
        $this->assign('donateCount', $itemLists['count']);
        $this->assign('itemLists', $itemLists['lists']);
        $this->display();
    }
    
    // 捐赠配置信息
    public function configAction()
    {
        $dProduct = D('DistributionShop');
        $product = $dProduct->find($this->aid);
        $product['donate_on'] = $this->getRadio('donate_on', $dProduct->donate_on, $product['donate_on']);
        $this->assign('product', $product);
        $this->display();
    }
    
    // 添加公益项目
    public function addProjectAction(){
        $this->display('saveProject');
    }

    // 添加公益项目
    public function modifyProjectAction(){
        $this->item = D('DistributionShopDonateProject')->find(I('id',0,'intval'));
        $this->display('saveProject');
    }
    
    // 保存公益项目
    public function saveProjectAction(){
        $model = D('DistributionShopDonateProject');
        $this->submitPost($model);
    }
    
    // 公益项目列表
    public function projectAction(){
        $this->itemLists = DistributionShopDonate::getDonateProjectLists($this->aid,true);
        $this->display();
    }
    
    // 设置状态
    public function setStatusProjectAction(){
        $this->ajaxSetStatus('DistributionShopDonateProject');
    }
    
    // 移除
    public function removeProjectAction(){
        $this->ajaxRemove('DistributionShopDonateProject');
    }
    
    /**
     * 保存捐赠配置
     */
    public function saveAction() {
        parent::submitPost('DistributionShop');
    }
    
}